package com.learn.sb.webfluxdemo.route;

import com.learn.sb.webfluxdemo.handler.UserHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;


@Configuration
public class UserRoute {

	@Bean
	@Autowired
	public RouterFunction<ServerResponse> routersFunction(UserHandler userHandler) {
		return RouterFunctions
				.route(RequestPredicates.GET("/api/users"), userHandler::getUserList)
				.and(RouterFunctions.route(RequestPredicates.GET("/api/user/{userId}"), userHandler::getUser));

	}
}
